<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <link href='/css/styles.css' rel='stylesheet' type='text/css' />
    <link href='/images/favicon.png' rel='shortcut icon' />
    <script src='/js/jquery.min.1.4.js'></script>
    <script src='/js/app.js'></script>
    <script src='/js/common.js'></script>
    
    <meta content='width=device-width, minimum-scale=1.0, maximum-scale=1.0' name='viewport' />
    <title>redis - 命令</title>
	<meta http-equiv="description" content="redis中文资料站，下载安装redis，查找redis常用命令（commands），选择适合的redis客户端方式，配置redis主从（master-slave），阅读redis官方文档，社区里了解更多redis信息，提交redis的bug。" />
	
  </head>
  <body class=''>
    <script src='/js/head.js'></script>
    <div class='text'>
      <h1 class='command'>
        <span id='command_name_span' class='name'></span>
        <span id='command_args_span' class='arg'></span>
      </h1>
      <article>
      	<aside>
        	<script type='text/javascript'>showCmdURL();</script>
        </aside>
        
        <div class='metadata'>
          <p><strong>加入版本 <span id='command_ver_span'></span>。</strong></p>
          <p><strong>时间复杂度：</strong> O(N)+O(M log(M))，N为给定有序集基数的总和，M为结果集的基数。</p>
        </div>
        
        <p>
计算给定的numkeys个有序集合的并集，并且把结果放到destination中。在给定要计算的key和其它参数之前，必须先给定key个数(numberkeys)。
默认情况下，结果集中某个成员的score值是所有给定集下该成员score值之和。</p><p>
使用WEIGHTS选项，你可以为每个给定的有序集指定一个乘法因子，意思就是，每个给定有序集的所有成员的score值在传递给聚合函数之前都要先乘以该因子。如果WEIGHTS没有给定，默认就是1。</p><p>
使用AGGREGATE选项，你可以指定并集的结果集的聚合方式。默认使用的参数SUM，可以将所有集合中某个成员的score值之和作为结果集中该成员的score值。如果使用参数MIN或者MAX，结果集就是所有集合中元素最小或最大的元素。</p><p>
如果key destination存在，就被覆盖。
</p>
        
        
        <h2>返回值</h2>
        <p><a href="/topics/protocol.html#integer-reply">整数</a>: 结果有序集合destination中元素个数。</p>
      
        <h2>例子</h2>
        <div class='example' data-session='556b53e476d6f538d45794f03b3bd98b'>
          <span class='monospace prompt'>redis>&nbsp;</span>
          <span class='monospace command'>ZADD zset1 1 "one"</span>
          <pre>(integer) 1</pre>
          <span class='monospace prompt'>redis>&nbsp;</span>
          <span class='monospace command'>ZADD zset1 2 "two"</span>
          <pre>(integer) 1</pre>
          <span class='monospace prompt'>redis>&nbsp;</span>
          <span class='monospace command'>ZADD zset2 1 "one"</span>
          <pre>(integer) 1</pre>
          <span class='monospace prompt'>redis>&nbsp;</span>
          <span class='monospace command'>ZADD zset2 2 "two"</span>
          <pre>(integer) 1</pre>
          <span class='monospace prompt'>redis>&nbsp;</span>
          <span class='monospace command'>ZADD zset2 3 "three"</span>
          <pre>(integer) 1</pre>
          <span class='monospace prompt'>redis>&nbsp;</span>
          <span class='monospace command'>ZUNIONSTORE out 2 zset1 zset2 WEIGHTS 2 3</span>
          <pre>(integer) 3</pre>
          <span class='monospace prompt'>redis>&nbsp;</span>
          <span class='monospace command'>ZRANGE out 0 -1 WITHSCORES</span>
          <pre>1) "one"&#x000A;2) "5"&#x000A;3) "three"&#x000A;4) "9"&#x000A;5) "two"&#x000A;6) "10"</pre><form>
            <span class='monospace prompt'>redis>&nbsp;</span>
            <input autocomplete='off' name='command' spellcheck='false' type='text' />
          </form></div>
        
      </article>
    </div>
    
    <script type='text/javascript'>startShow();</script>
    <div class='text' id='comments'>
      <div id='disqus_thread'></div>
      <script type='text/javascript'>
        //<![CDATA[
          var disqus_shortname = 'rediscn';
          
          // The following are highly recommended additional parameters. Remove the slashes in front to use.
          var disqus_identifier = 'command_'+curCommandObj.key;
          var disqus_url = curCommandObj.getdisqusUrl();
          
          /* * * DON'T EDIT BELOW THIS LINE * * */
          (function() {
            var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
              dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
              (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
          })();
        //]]>
      </script>
      <a class='dsq-brlink' href='http://disqus.com'>
        Comments powered by
        <span class='logo-disqus'>
          Disqus
        </span>
      </a>
    </div>

    
    <script src='/js/foot.js'></script>
    
  </body>
</html>
